package com.kedacom.ctsp.authz.access;

import com.kedacom.ctsp.authz.entity.AuthResource;

import java.util.Comparator;
import java.util.Set;

/**
 * 数据权限的工具类
 *
 * @author sunchenjie
 * @create 2018-01-15 16:12
 **/
public class DataAccessUtil {

    /**
     * 根据资源获取最大的权限
     *
     * @param resources
     * @return
     */
    public static DataAccessScopeEnum getDataScopeByResources(Set<AuthResource> resources) {
        return resources.stream()
                .filter(r -> r.getDataScope() != null)
                .map(AuthResource::getDataScope)
                .max(Comparator.comparing(r -> r.ordinal()))
                .orElse(DataAccessScopeEnum.SELF);
    }
}